package logic

import (
	"context"

	"worker/sse/internal/svc"
	"worker/sse/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendToGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendToGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendToGroupLogic {
	return &SendToGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SendToGroupLogic) SendToGroup(req *types.SendToGroupReq) (resp *types.SendToGroupResp, err error) {
	resp = &types.SendToGroupResp{}

	l.svcCtx.SSE.SendToGroup(req.GroupId, req.Msg)

	return resp, nil
}
